cmake_minimum_required(VERSION 3.20)

project(ffmpeg_sdl_player)
set(CMAKE_CXX_STANDARD 17)

set(FFMPEG_DEV_ROOT "D:/Apps/ffmpeg")
include_directories(include)

file(GLOB ffmpeg_shared_libries ${FFMPEG_DEV_ROOT}/bin/*dll)

find_package(SDL3 CONFIG REQUIRED PATHS "F:/libs/SDL3-3.2.0")
get_target_property(SDL3_LIB SDL3::SDL3 LOCATION)
# 配置包含目录和库
if (MSVC)
    # 强制 MSVC 使用 UTF-8 编码
    add_compile_options(/utf-8)
endif ()
if (!FFMPEG_DEV_ROOT)
    find_package(FFMPEG REQUIRED)
endif ()

#message("FFMPEG_DIR ${FFMPEG_DIR}")
add_executable(ffmpeg_sdl_player src/main.cpp
        include/AudioOutput.h
        include/VideoOutput.h
        include/DecodeThread.h
        include/AVFrameQueue.h
        include/AVPacketQueue.h
        include/DemuxThread.h
        include/Queue.h
        include/Log.h
        include/Thread.h
        src/Log.cpp
        src/DemuxThread.cpp
        src/AVPacketQueue.cpp
        src/AVFrameQueue.cpp
        src/DecodeThread.cpp
        src/AudioOutput.cpp
        src/VideoOutput.cpp
)

if (WIN32)
    add_custom_command(TARGET ffmpeg_sdl_player POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
            "${SDL3_LIB}"
            $<TARGET_FILE_DIR:ffmpeg_sdl_player>
            COMMENT "copy sdl3 dll..."
    )
endif ()
if (WIN32)
    foreach (FFMPEG_DLL ${ffmpeg_shared_libries})
        message("FFMPEG_DLL ${FFMPEG_DLL}")
        add_custom_command(TARGET ffmpeg_sdl_player POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${FFMPEG_DLL}"
                $<TARGET_FILE_DIR:ffmpeg_sdl_player>
                COMMENT "copy ${FFMPEG_DLL}"
        )
    endforeach ()
endif ()

target_include_directories(ffmpeg_sdl_player
        PRIVATE
        ${FFMPEG_DEV_ROOT}/include
)
target_link_directories(ffmpeg_sdl_player
        PRIVATE
        ${FFMPEG_DEV_ROOT}/lib
)
target_link_libraries(ffmpeg_sdl_player PRIVATE
        SDL3::SDL3
        avcodec
        avformat
        avfilter
        avdevice
        swresample
        swscale
        avutil
)